<template>
	<uv-popup ref="popupRef" mode="right">
		<view class="popup-dia">
			<scroll-view scroll-y style="height: calc(100vh - 160rpx);">
				<view class="card" v-for="(item, index) in allList" :key="index">
					<view class="title">{{ item.title }}</view>
					<view class="btns">
						<button class="cu-btn" :class="{ 'cu-btn-active': item.active === el.name }"
							v-for="(el, n) in item.childer" :key="el.name" @click="handSelect(item, el)">
							{{ el.name }}
						</button>
					</view>
				</view>
			</scroll-view>
			<view class="action">
				<button class="cu-btn" @click="handReset">重置</button>
				<button class="cu-btn" @click="handSubmit">确定</button>
			</view>
		</view>
	</uv-popup>
</template>

<script setup>
	import {
		reactive,
		ref
	} from 'vue'
	const allList = ref([{
		title: '动力类型',
		active: '',
		childer: [{
			name: '汽油'
		}, {
			name: '纯电'
		}, {
			name: '油电混'
		}, {
			name: '插电混'
		}]
	}, {
		title: '年限',
		active: '',
		childer: [{
			name: '全部'
		}, {
			name: '1年'
		}, {
			name: '2年'
		}, {
			name: '3年'
		}, {
			name: '4年'
		}, {
			name: '5年'
		}]
	}, {
		title: '变速箱',
		active: '',
		childer: [{
			name: '全部'
		}, {
			name: '手动'
		}, {
			name: '自动'
		}]
	}, {
		title: '车辆级别',
		active: '',
		childer: [{
			name: '全部'
		}, {
			name: '快车'
		}, {
			name: '专车'
		}, {
			name: '豪华车'
		}]
	}, {
		title: '续航里程',
		active: '',
		childer: [{
			name: '全部'
		}, {
			name: '80km'
		}, {
			name: '100km'
		}, {
			name: '200km'
		}, {
			name: '250km'
		}, {
			name: '300km'
		}, {
			name: '400km'
		}, {
			name: '430km'
		}, {
			name: '450km'
		}, {
			name: '500km'
		}]
	}])
	const handSelect = (item, el) => {
		if (item.active === el.name) {
			item.active = ''
		} else {
			item.active = el.name
		}
	}
	const handReset = () => {
		allList.value.map(el => {
			el.active = ''
			return el
		})
	}
	const handSubmit = () => {
		uni.$uv.toast('开发中...')
		popupRef.value.close()
	}
	const popupRef = ref(null)
	const handOpen = () => {
		popupRef.value.open()
	}
	defineExpose({
		handOpen
	})
</script>

<style lang="scss" scoped>
	.popup-dia {
		width: 600rpx;
		height: 100vh;
		padding: 24rpx;
		box-sizing: border-box;
		position: relative;
		display: flex;
		flex-direction: column;

		.card {
			&:not(:first-child) {
				margin-top: 40rpx;
			}

			.title {
				font-size: 32rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #333333;
			}

			.btns {
				display: flex;
				flex-wrap: wrap;
				gap: 20rpx;
				margin-top: 24rpx;

				.cu-btn {
					width: 158rpx;
					height: 68rpx;
					background: #F5F5F5;
					border-radius: 10rpx 10rpx 10rpx 10rpx;
					font-size: 26rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
					margin: 0;
					border: 1rpx solid #F5F5F5;

					&::after {
						border: none;
					}

					&-active {
						background: #FFF7E4;
						color: #FF930D;
						border-color: #FF930D;
					}
				}
			}
		}

		.action {
			position: absolute;
			width: calc(100% - 48rpx);
			bottom: 20rpx;
			bottom: calc(constant(safe-area-inset-bottom) + 20rpx);
			bottom: calc(env(safe-area-inset-bottom) + 20rpx);
			display: flex;
			align-items: center;
			justify-content: space-between;

			.cu-btn {
				width: 258rpx;
				height: 90rpx;
				background: #F5F5F5;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				font-size: 30rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				display: flex;
				align-items: center;
				justify-content: center;

				&::after {
					border: none;
				}

				&:last-child {
					background-color: #FFC434;
				}
			}
		}
	}
</style>